<template>
	<el-dialog title="服务调用配置" :visible.sync="dialogVisible" width="800" @close="handleClose"
		:close-on-click-modal="false"
		:append-to-body="true">
		<div slot="title" class="dialog-header-title">
			<i class="el-icon-edit-outline"></i>
			<span>服务调用配置</span>
		</div>

		<div class="smp-search" v-if="dialogVisible">
			<el-form :inline="false" label-width="150px" size="mini"  ref="form" :model="form" :rules="rules">

				<el-row>
						<el-col :span="24">
							<el-form-item label="资源类型:" prop="sourceType" >
								<el-input v-model="form.sourceType" disabled placeholder="资源类型"></el-input>
							</el-form-item>
						</el-col>

						<el-col :span="24">
							<el-form-item label="资源名称:" prop="sourceName">
								<el-input v-model="form.sourceName" placeholder="资源名称"></el-input>
							</el-form-item>
						</el-col>
						
						<el-col :span="24">
							<el-form-item label="资源路径:" prop="sourcePath">
								<el-input v-model="form.sourcePath" placeholder="资源路径"></el-input>
							</el-form-item>
						</el-col>
						
						<el-col :span="24">
							<el-form-item label="资源描述:" prop="sourceDesc">
								<el-input v-model="form.sourceDesc" placeholder="资源描述"></el-input>
							</el-form-item>
						</el-col>
				</el-row>
			</el-form>
		</div>
		<span slot="footer" class="dialog-footer">
			<el-button size="mini"  type="primary" @click="onSubmit">确定</el-button>
			<el-button size="mini"   @click="closeDialog">取消</el-button>
		</span>
	</el-dialog>
</template>

<script>
	"use strict";
	import { addEsbSourceInfo } from '@/api/source.js';

	export default {
		
		data() {
			return {
				dialogVisible: false,
				rules: {
					sourceType: [{
						required: true,
						message: "资源类型不能为空",
						trigger: ['blur', 'change']
					}],
					sourceName: [{
						required: true,
						message: "资源名称不能为空",
						trigger: ['blur', 'change']
					}],
					sourcePath: [{
						required: true,
						message: "资源路径不能为空",
						trigger: ['blur', 'change']
					}]
				},
				form: {
					sourcePath: '',
					sourceType: '',
					sourceName: '',
					sourceDesc: ''
				},

			};
		},


		methods: {
			
			onSubmit() {
				this.addEsbSourceInfo();
			},
						
			addEsbSourceInfo() {
				this.$refs["form"].validate(valid => {
					if (valid) {
						addEsbSourceInfo(this.form).then(response => {
							if(response.data.code == "0000"){
								this.$message.success(response.data.message);
								// this.$message({
						//duration:5000,
								// 	type: 'success',
								// 	message: '核心路由新增成功！'
								// });
								this.dialogVisible = false;
								this.$emit("changeProxyPath",this.form.sourcePath);
								this.reset();
							}else{
								this.$message.error(response.data.message);
							}
						}).catch(error => {
							this.$message({
						duration:5000,								type: 'error',
								message: '核心路由新增失败！'
							});
							this.reset();
							this.dialogVisible = false;
						});
					}
				})

			},
			
			
			
			showDialog(sourceType) {
				this.form.sourceType = sourceType;
				this.dialogVisible = true;

			},

			closeDialog() {
				this.reset();
				this.dialogVisible = false;
			},

			handleClose() {
				this.reset();
				this.dialogVisible = false;
			}


		},

	}
</script>

<style>
</style>
